/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.DomainBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Domain;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Provisioning.CountAccountResult;
/*    */ import com.zimbra.cs.account.Provisioning.CountAccountResult.CountAccountByCos;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CountAccount
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public boolean domainAuthSufficient(Map context)
/*    */   {
/* 44 */     return true;
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*    */   {
/* 49 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 50 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 52 */     Element d = request.getElement("domain");
/* 53 */     String key = d.getAttribute("by");
/* 54 */     String value = d.getText();
/*    */     
/* 56 */     Domain domain = prov.get(Key.DomainBy.fromString(key), value);
/*    */     
/* 58 */     if (domain == null) {
/* 59 */       throw AccountServiceException.NO_SUCH_DOMAIN(value);
/*    */     }
/* 61 */     checkDomainRight(zsc, domain, Rights.Admin.R_countAccount);
/*    */     
/* 63 */     Element response = zsc.createElement(AdminConstants.COUNT_ACCOUNT_RESPONSE);
/* 64 */     Provisioning.CountAccountResult result = Provisioning.getInstance().countAccount(domain);
/* 65 */     toXML(response, result);
/* 66 */     return response;
/*    */   }
/*    */   
/*    */   private void toXML(Element parent, Provisioning.CountAccountResult result) {
/* 70 */     for (Provisioning.CountAccountResult.CountAccountByCos c : result.getCountAccountByCos()) {
/* 71 */       Element eCos = parent.addElement("cos");
/* 72 */       eCos.addAttribute("id", c.getCosId());
/* 73 */       eCos.addAttribute("name", c.getCosName());
/* 74 */       eCos.setText(String.valueOf(c.getCount()));
/*    */     }
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 80 */     relatedRights.add(Rights.Admin.R_countAccount);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CountAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */